package com.abetsy.vben.api;

import com.abetsy.vben.entity.GlobalConfig;
import com.abetsy.vben.param.RegisterParam;
import com.abetsy.vben.service.GlobalConfigService;
import com.abetsy.vben.service.SysUserService;
import com.abetsy.vben.utils.api.ResultData;
import com.abetsy.vben.vo.UserInfoVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "*")
public class UserController {

    @Resource
    private SysUserService userService;

    @Resource
    private GlobalConfigService globalConfigService;

    @GetMapping("/info")
    public ResultData<UserInfoVo> login() {
        return ResultData.success(userService.info());
    }

    /**
     * 获取用户全局设置
     */
    @GetMapping("/get/config")
    public ResultData<GlobalConfig> getConfig() {
        return ResultData.success(globalConfigService.getConfig());
    }

    /**
     * 设置用户全局设置
     */
    @PostMapping("/set/config")
    public ResultData<GlobalConfig> setConfig(@RequestBody @Validated GlobalConfig globalConfig) {
        return ResultData.success(globalConfigService.setConfig(globalConfig));
    }

    /**
     * 用户新增
     */
    @PostMapping("/add")
    public ResultData<Object> userAdd(@RequestBody @Validated RegisterParam registerParam) {
        return ResultData.success(userService.userAdd(registerParam));
    }

}
